package com.mine.controller;

import com.mine.common.helper.GsonHelper;
import com.mine.common.helper.QiNiuHelper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@Controller
public class PicController {

    @RequestMapping("/pic/upload")
    @ResponseBody
    public Object uploadImage(MultipartFile uploadFile) {
        Map map = new HashMap();
        try {
            String url = QiNiuHelper.uploadImage(uploadFile.getBytes());
            map.put("error", 0);
            map.put("url", url);
            return GsonHelper.toJson(map);
        } catch (Exception e) {
            map.put("error", 1);
            map.put("message", "图片上传失败");
            return GsonHelper.toJson(map);
        }


    }


}
